package com.example.延迟队列插件版;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;

import java.util.HashMap;
import java.util.Map;

/**
 * 延迟队列插件版
 * 准备工作:
 *  1.安装插件 https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases(选择与自己MQ版本对应的插件)
 *  2.下载其中的.ez复制到mq容器内的plugins目录下
 *  3.进入docker容器 启动插件 rabbitmq-plugins enable rabbitmq_delayed_message_exchange
 *  4.通过此条命令查看插件是否安装成功 rabbitmq-plugins list 然后可以退出容器了
 */
//@Configuration
public class DelayPluginsConfig {

    public static final String DELAY_PLUGIN_QUEUE = "delay_plugin_queue";

    public static final String DELAY_PLUGIN_EXCHANGE = "delay_plugin_exchange";

   // @Bean
    Queue delayPluginQueue() {
        return new Queue(DELAY_PLUGIN_QUEUE, true, false, false);
    }


   // @Bean
    CustomExchange delayPluginExchange() {
        Map<String, Object> ags=new HashMap<>();
        //指定此交换机为直连交换机
        ags.put("x-delayed-type", "direct");
        return new CustomExchange(DELAY_PLUGIN_EXCHANGE,"x-delayed-message",true,false,ags);
    }


   // @Bean
    Binding delayPluginBinding() {
        return BindingBuilder
            .bind(delayPluginQueue()).to(delayPluginExchange()).with(DELAY_PLUGIN_QUEUE).noargs();
    }


}
